/**
 * Project Name:jbase
 * File Name:BeanInfo.java
 * Package Name:jbase.project.system.core.ioc
 * Date:2017年4月22日下午6:02:57
 * Copyright (c) 2017, chenzhou1025@126.com All Rights Reserved.
 *
*/

package jbase.project.system.core.ioc;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;

/**
 * ClassName:BeanInfo <br/>
 * Function: TODO ADD FUNCTION. <br/>
 * Reason: TODO ADD REASON. <br/>
 * Date: 2017年4月22日 下午6:02:57 <br/>
 * 
 * @author Licheng
 * @version
 * @since JDK 1.8
 * @see
 */
public class BaseInstance {

	private String id;
	private String name;
	private String desc;
	private Class<?> type;
	private String className;
	private Object instance;
	private Boolean isCreated = false;
	private Map<String, Object> properties = new HashMap<>();

	public void setProperty(String propName, String propValue) {
		properties.put(propName, propValue);
	}

	public <T> T getProperty(String propName) {
		return (T) properties.get(propName);
	}

	public String getClassName() {
		return className;
	}

	public void setClassName(String className) {
		this.className = className;
	}

	public Boolean getIsCreated() {
		return isCreated;
	}

	public void setIsCreated(Boolean isCreated) {
		this.isCreated = isCreated;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getDesc() {
		return desc;
	}

	public void setDesc(String desc) {
		this.desc = desc;
	}

	public Class<?> getType() {
		return type;
	}

	public void setType(Class<?> type) {
		this.type = type;
	}

	public Object getInstance() {
		return instance;
	}

	public void setInstance(Object instance) {
		this.instance = instance;
	}

	public String toString() {
		try {
			Class<BaseInstance> clazz = (Class<BaseInstance>) getClass();
			Field[] fields = clazz.getFields();
			StringBuffer s = new StringBuffer();
			for (Field field : fields) {
				s.append(field.getName() + "=" + field.get(this));
			}
			return s.toString();
		} catch (Exception e) {
			e.printStackTrace();
			return "cannot list fields!";
		}
	}

}
